<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.List" %>
<%@ page import="dto.OperatoerDTO" %>
<jsp:useBean id="func" class="Function.Functions" scope="session"></jsp:useBean>
<html>
	<head>
		<link rel="stylesheet" type="text/css" href="style.css">
		<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
		<title>Edit Brugere</title>
	</head>
<body>
<div id="Centring">
<div class="sidenavn">Brugere</div>
<div id="Top"><div class="menu">
			<form method="POST">
				<table width=100%> 
					<tr>
						<td>
						<%= session.getAttribute("menu") %>
						</td>
						<td align="right">
						<% 
						OperatoerDTO tempOpr = (OperatoerDTO)session.getAttribute("loginID");
						%>
						<input type="submit" name="link" value="Edit Profile" class="hyperlinkButton" size=1>
						<input type="submit" name="link" value="log out" class="hyperlinkButton">
						</td>
					</tr>
				</table>
			</form>
</div></div>
<div id="Main">
	<br>
	<hr width=95% border=1>
	<br>
	<div class="Titlelille">Edit Bruger</div>
	Indtast nye informationer og tryk edit
	<div class="Indhold">	

<form method="POST">


<%
int oprNumber = 0;

if(request.getMethod().equals("POST") && request.getParameter("userRedirect") != null){
	int temp = Integer.parseInt(request.getParameter("userRedirect"));
	oprNumber = temp;
}

if(request.getMethod().equals("POST") && request.getParameter("oprNumber") != null){
	int temp = Integer.parseInt(request.getParameter("oprNumber"));
	oprNumber = temp;
}

out.print("<input type=\"hidden\" name=\"oprNumber\" value=\""+oprNumber+"\">");

if(request.getParameter("edit") != null){
	int oprID = oprNumber;
	String oprCPR = request.getParameter("oprcpr");
	String oprNavn = request.getParameter("oprNavn");
	String oprINI = func.generateINI(oprNavn);
	String oprPassword = request.getParameter("Password");
	String oprRights = request.getParameter("rights");
	func.updateOperaoer(new OperatoerDTO(oprID, oprNavn, oprINI , oprCPR, oprPassword, oprRights));
}

if(request.getMethod().equals("POST") && request.getParameter("delete") != null){
	func.deleteOperatoer(oprNumber);
	out.print("Succes!");
}


OperatoerDTO tempOperator = func.getOperatoer(oprNumber);

		



if(tempOperator != null){
out.print("<br>");
out.print("<table id=\"tabledesign\" align=center width=100% >");
out.print("<tr>");
	out.print("<th>ID</th>"); 
	out.print("<th>Navn</th>");
	out.print("<th>INI</th>"); 
	out.print("<th>Cpr</th>");
	out.print("<th>Password</th>");
	out.print("<th>Rights</th>");
	out.print("<th>Valg</th>");
out.print("</tr>");
out.print("<tr>");
	out.print("<td>"+tempOperator.getOprId()+"</td>"); 
	out.print("<td>"+"<input type=\"text\" name=\"oprNavn\" value=\""+tempOperator.getOprNavn()+"\" size=15>"+"</td>");
	out.print("<td>"+tempOperator.getIni()+"</td>");; 
	out.print("<td>"+"<input type=\"text\" name=\"oprcpr\" value=\""+tempOperator.getCpr()+"\"size=10>"+"</td>");
	out.print("<td>"+"<input type=\"text\" name=\"Password\" value=\""+tempOperator.getPassword()+"\"size=10>"+"</td>");
	out.print("<td>"+"<select name=\"rights\">");
if(tempOperator.getRights().equals("admin")){
	out.print("<option value=admin selected>admin</option>");
}else{
	out.print("<option value=admin>admin</option>");
}
if(tempOperator.getRights().equals("farma")){
	out.print("<option value=farma selected>farma</option>");
}else{
	out.print("<option value=farma>farma</option>");
}
if(tempOperator.getRights().equals("vaerk")){
	out.print("<option value=vaerk selected>vaerk</option>");
}else{
	out.print("<option value=vaerk>vaerk</option>");
}
if(tempOperator.getRights().equals("opr")){
	out.print("<option value=opr selected>opr</option>");
}else{
	out.print("<option value=opr>opr</option>");
}
if(tempOperator.getRights().equals("inactive")){
	out.print("<option value=inactive selected>inactive</option>");
}else{
	out.print("<option value=inactive>inactive</option>");
}

	out.print("</select></td>");
	out.print("<td> <button type=\"submit\" name=\"edit\" value=\"Edit\" class=\"hyperlinkButton\">SAVE</button> </td>");
out.print("</tr>");
out.print("</table>");
out.print("<CENTER>");
if(!tempOperator.getRights().equals("opr") || tempOpr.getOprNavn().equals("DEBUG"))
	out.print("<br>"+"<input type=submit name=\"delete\" value=\"Delete User\">");
out.print("</CENTER>");
}
%>


</form>
<br>
</div>
</div>
<div id="Bund"></div>


</div>	
</body>
</html>